﻿using System;
using Newtonsoft.Json;

namespace TemplateTool.ConvertExtension
{
    public static class JsonConvertExtension
    {
        public static string ToJson<T>(this T t) where T : class
        {
            return JsonConvert.SerializeObject(t);
        }

        public static T ToObject<T>(this string str)
        {
            try
            {
                return JsonConvert.DeserializeObject<T>(str);
            }
            catch (Exception ex)
            {
                return default;
            }
        }


    }
}

